package com.example.points.schedule;

import com.example.points.service.UserPointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PointsExpirationScheduler {

    @Autowired
    private UserPointsService userPointsService;

    /**
     * 每天凌晨1点执行过期积分处理
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void handleExpiredPoints() {
        log.info("开始处理过期积分...");
        try {
            userPointsService.handleExpiredPoints();
            log.info("过期积分处理完成");
        } catch (Exception e) {
            log.error("处理过期积分时发生错误", e);
        }
    }
} 